import 'package:flutter/material.dart';

//ListView列表组件
void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('flex组件'),
          backgroundColor: Colors.green[100],
        ),
        body: MyHomePage(),
      ),
    );
  }
}

class MyHomePage extends StatelessWidget {
  MyHomePage({super.key});

  @override
  Widget build(BuildContext context) {
    //Row组件
    return Flex(
      direction:Axis.horizontal,
      children: [
        Expanded(
          child: IconContainer(Icons.settings, color: Colors.green),
          flex: 1,//这个元素设置宽度是没有效果
        ),
         IconContainer(Icons.home),

        // IconContainer(Icons.home),
        // IconContainer(Icons.search, color: Colors.blue),
        // IconContainer(Icons.settings, color: Colors.green),
      ],
    );
  }
}

class IconContainer extends StatelessWidget {
  final Color color;
  final IconData icon;
  const IconContainer(this.icon, {super.key, this.color = Colors.red});

  @override
  Widget build(BuildContext context) {
    return Container(
      alignment: Alignment.center,
      width: 120,
      height: 120,
      color: this.color,
      child: Icon(icon, size: 28, color: Colors.white),
    );
  }
}
